#include <windows.h>
#include <winhttp.h>
#include <stdarg.h>
#include <intrin.h>
#include <stdbool.h>

#define HOSTNAME L"www.baidu.com"
#define URLPATH L"/"

void mainCRTStartup()
{
    HINTERNET hOpen = WinHttpOpen(NULL, WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY, NULL, NULL, 0);
    HINTERNET hConnect = WinHttpConnect(hOpen, HOSTNAME, INTERNET_DEFAULT_HTTPS_PORT, 0);
    HINTERNET hRequest = WinHttpOpenRequest(hConnect, NULL, URLPATH, NULL, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_SECURE);
    HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
    DWORD dwSize = 0;
    WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0);
    WinHttpReceiveResponse(hRequest, NULL);
    do
    {
        DWORD i;
        char buf[0x100];
        WinHttpQueryDataAvailable(hRequest, &dwSize);
        for (i = 0; i < dwSize; i += 0x100)
        {
            DWORD dwRead = 0;
            WinHttpReadData(hRequest, buf, 0x100, &dwRead);
            WriteConsoleA(hStdOut, buf, dwRead, NULL, NULL);
        }
    } while (dwSize);
    WinHttpCloseHandle(hRequest);
    WinHttpCloseHandle(hConnect);
    WinHttpCloseHandle(hOpen);
    ExitProcess(0);
}